﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Windows.Forms;

namespace Tommy
{
    public class Browser
    {
        IUIBrowser uiBrowser;
        IUINavigator uiNavigator;
        public void InitializeEventTable()
        {
            EventTable.event_browser_initialize += OnBrowser_LoadPlugin;
            EventTable.event_browser_show += OnBrowser_Show;            
        }

        private bool OnBrowser_LoadPlugin(ref Context context)
        {           
            uiBrowser = System.Activator.CreateInstance("Tommy.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d63bf6103442dbdd", "Tommy.UIBrowser").Unwrap() as IUIBrowser;
            
            return true;
        }

        private bool OnBrowser_Show(ref Context context)
        {
            Application.Run(uiBrowser as Form);
            return true;
        }

        private bool OnNavigator_LoadPlugin(ref Context context)
        {
            uiNavigator = System.Activator.CreateInstance("Tommy.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d63bf6103442dbdd", "Tommy.UINavigator").Unwrap() as IUINavigator;
            return true;
        }

        private bool OnNavigator_Show(ref Context context)
        {
            uiNavigator.SetParent(uiBrowser as Form);
            uiNavigator.Visibled = true;
            return true;
        }
    }
}
